package ru.stork.vasilisa.model

import ru.stork.vasilisa.lang
import com.yelbota.util.$lazy
import com.wordpress.michid.Memoize._

object Variant {

  private def _fromNode(foreingNs: Namespace, t: lang.Variant): VasilisaType = {

    val ns = VasilisaType.nsReconfigureWithPrivates(foreingNs, t)

    new Variant(
      ns = ns,
      node = t,
      name = t.name,

      typeParameters = t.params match {
        case Some(x) => x toSet
        case None => Set()
      },

      variants = t.declarations.collect { case x: lang.Property => x }
        .map(x => Property.fromNode(ns, x)) toSet
    )
  }

  val fromNode = memoize(_fromNode _)

}

class Variant(ns: Namespace,
              name: String,
              node: lang.Node,
              typeParameters: Set[String],

              val variants: Set[Property])

  extends VasilisaType(ns, name, node, typeParameters)